<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>上海市审计地理信息分析平台</title>
  <link href="css/login.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="js/basic/jquery.js"></script>
  <script type="text/javascript" src="js/basic/pidcrypt.js"></script>
  <script type="text/javascript" src="js/basic/md5.js"></script>

</head>

<body>
  <div class="login_box">
    <div class="logo"><img src="img/logo.png" alt="" /></div>
    <div class="login">
      <div class="login_name">
        <p>用户登录</p>
      </div>
      <div class="inputs">
        <div class="yhm">
          <img src="img/user.png" alt="" /><input id="usernameipt" type="text" placeholder="请输入用户名" />
        </div>
        <div class="pwd">
          <img src="img/lock.png" alt="" /><input type="password" id="password" placeholder="请输入密码" />
        </div>
        <!-- <div class="yzhm">
            <img src="img/safe.png" alt="" />
            <input type="text" placeholder="请输入验证码" />
            <img class="yzhmpic" src="img/yzhm.png" alt="" />
          </div> -->
        <button id="loginbt">登录</button>
      </div>
    </div>
  </div>
</body>
<script type="text/javascript">
  function init() {
    $('#loginbt').click(function () {
      // $.ajax({
      //   type: "POST",
      //   url: "MapServlet",
      //   dataType: "json",
      //   data: {
      //     commandCode: "userLogin",
      //     userName: $('#usernameipt').val(),
      //     password: $('#password').val()
      //   },
      //   success: function (result) {
      //     if (result == true) {
      //       // var link = "index.html" + "?para1=" + $('#usernameipt').val();
      //       // var link = "index.html";
      //       var link = "main.html";
      //       window.location.href = link;
      //     } else {

      //       alert("用户密码不正确");

      //     }
      //   }
      // });


      var pass = $('#password').val()
      var password = pidCrypt.MD5(pass);

      $.ajax({
        type: "POST",
        url: "Loginservlet",
        dataType: "json",
        data: {
          username: $('#usernameipt').val(),
          password: password
        },
        success: function (result) {
          if (result == false) {
            alert("登录失败");
          } else {
            const {
              USERNAME,
              ROLE,
              ALIAS
            } = result;
            sessionStorage.username = USERNAME;
            sessionStorage.role = ROLE;
            sessionStorage.alias = ALIAS;
            var link = "main.html";
            window.location.href = link;
          }
        }
      });
    });

    $(document).keydown(function (event) {
      if (event.keyCode == 13) {
        $('#loginbt').triggerHandler('click');
      }
    })
  };

  $(function () {
    init();
  });
</script>

</html>